package net.jxvtc.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;



import net.jxvtc.pojo.DevUser;
import net.jxvtc.service.devuser.DevUserService;
import net.jxvtc.tools.Constants;


@Controller
@RequestMapping(value="/devUser")
public class LoginController {
	private Logger logger = Logger.getLogger(LoginController.class);
	
	@Resource
	private DevUserService devUserService;;
	
	@RequestMapping(value="/login")
	public String login(){
		logger.debug("LoginController welcome AppInfo==================");
		return "devlogin";
	}
	
	@RequestMapping(value="/dologin",method=RequestMethod.POST)
	public String doLogin(@RequestParam String devCode,@RequestParam String devPassword,HttpServletRequest request,HttpSession session) throws Exception{
		logger.debug("doLogin====================================");
		DevUser devUser=devUserService.login(devCode, devPassword);
		if(null!=devUser)
		{
			session.setAttribute(Constants.DEV_USER_SESSION, devUser);
			return "redirect:/devUser/flatform/main";
		}
		else
		{
			request.setAttribute("error", "用户名或密码不正确");
			return "login";
		}
		
	}
	@RequestMapping(value="/logout")
	public String logout(HttpSession session){
		//清除session
		session.removeAttribute(Constants.DEV_USER_SESSION);
		return "devlogin";
	}
	
	@RequestMapping(value="/flatform/main")
	public String main(){
		return "developer/main";
	}
}
